<%@ page import="java.util.List" %>
<%@ page import="com.tlc.bean.Book" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>queryBooks</title>
    <style>
        body {
            background-color: darkkhaki;
        }

        table {
            position: relative;
            margin-top: 30px;
            background-color: coral;
            left: 30px;
        }

        p {
            font-size: 20px;
        }

        #name {
            width: 180px;
            height: 25px;
            border-radius: 8px;
            border: 2px solid gray;
        }

        #classify {
            width: 100px;
            height: 20px;
            border-radius: 3px;
        }

        #cover {
            display: inline-block;
            margin-left: 50px;
            margin-top: 10px;
            background-color: darkkhaki;
        }
        td {
            text-align: center;
        }

    </style>

    <script>
        <%--        是否删除--%>
        function deletefun(id, cover, currentPage, pageSize) {
            if (confirm("是否要删除记录？")) {

                location.href = "BookServlet?method=deleteBook&id=" + id + "&cover=" + cover + "&currentPage=" + currentPage + "&pageSize=" + pageSize;
            }
        }

        function clearfun() {
            document.getElementById("name").value = "";
            document.getElementById("classify").selected = "selected";
        }

        //下拉列表改变
        function changefun() {
            var pageSize = document.getElementById("chan").value;
            location.href = "BookServlet?method=queryBooks&pageSize=" + pageSize;
        }

        function pagefun(currentPage) {
            var url = "BookServlet?method=queryBooks&currentPage=" + currentPage +"&sname=${sname}&classify=${classify}&pageSize=${pageSize}&totalCount=${pu.totalCount}";
            location.href = url;
        }
    </script>

</head>


<body>
<form action="BookServlet?method=queryBooks&pageSize=${pageSize}" method="POST">
    搜索图书：<input type="text" name="sname" id="name" value=${sname}>
    <select name="classify">
        <option id="classify" value="0">图书种类</option>
        <option value="1" ${"1" eq classify ? "selected" : ""}>小说</option>
        <option value="2"${"2" eq classify ? "selected" : ""}>儿童读物</option>
        <option value="3"${"3" eq classify ? "selected" : ""}>摄影绘画</option>
        <option value="4"${"4" eq classify ? "selected" : ""}>非小说类</option>
        <option value="5"${"5" eq classify ? "selected" : ""}>科技类</option>
    </select>
    <input type="submit" value="搜索">
    <input type="button" value="清空" onclick="clearfun()">
</form>
<table border="2px" cellpacing="0px" cellpadding="0px" width="1000px">
    <tr>
        <td colspan="10" style="font-size: 20px;text-align: center">新图上架了,欢迎光临XXX书店！</td>
    </tr>
    <tr height="50px">
        <th>图书编号</th>
        <th>书名</th>
        <th>价格</th>
        <th>作者</th>
        <th>出版社</th>
        <th>图书封面</th>
        <th>出版日期</th>
        <th>圖書數量</th>
        <th>售否</th>
        <th>其他操作</th>
    </tr>
    <c:forEach items="${list}" var="book" varStatus="vs">

        <tr>
                <%--           自增计数 <td>${va.count}</td>--%>
            <td>${book.sid}</td>
            <td>${book.sname}</td>
            <td>${book.price}</td>
            <td>${book.auther}</td>
            <td>${book.phouse}</td>
            <td align="center">
                <img src="/image/${book.cover}" alt="" width="45px" height="30px">
            </td>
            <td>${book.dtime}</td>
            <td>${book.bcount}</td>
            <td>${book.nsale}</td>
            <td colspan="3">
                <a href="BookServlet?method=bookdetails&sid=${book.sid}&flag=delete">图书详情</a>
                <a href="javascript:deletefun(${book.sid},'${book.cover}',${pu.currentPage},${pageSize})">删除</a>
                <a href="BookServlet?method=bookdetails&sid=${book.sid}&flag=change&currentPage=${pu.currentPage}&pageSize=${pageSize}">修改</a>
            </td>
        </tr>
    </c:forEach>
</table>

<table id="cover">
    <tr>
        <td><a href="javascript:pagefun(1)">首页</a></td>
        <td><a href="javascript:pagefun('${pu.prePage}')">上一页</a></td>
        <td><a href="javascript:pagefun('${pu.nextPage}')">下一页</a></td>
        <td>            <a href="javascript:pagefun('${pu.totalPages}')">尾页</a>
        </td>
        <td>当前页:<span>${pu.currentPage}</span>/<span>${pu.totalPages}</span></td>
        <td>总记录数：<span>${pu.totalCount}</span></td>
        <td>
            选择页容量：
            <select name="pageSize" onchange="changefun()" id="chan">
                <option>5</option>
                <option ${pageSize eq 8 ? "selected" : "" }>8</option>
                <option ${pageSize eq 10 ? "selected" : "" }>10</option>
                <option ${pageSize eq pu.totalCount ? "selected" : "" }>${pu.totalCount}</option>
            </select></td>
    </tr>
</table>
</body>
</html>
